<template>
  <el-button
    :title="tip"
    v-bind="$attrs"
    v-on="listeners"
    :loading="loading"
  >
    <slot/>
  </el-button>
</template>

<script>
export default {
  name: 'EasyButton',
  inheritAttrs: false,
  props: {
    tip: String
  },
  data: function () {
    return {
      loading: false
    }
  },
  computed: {
    listeners: function () {
      const self = this
      return Object.assign({},
        // 我们从父级添加所有的监听器
        self.$listeners,
        // 然后我们添加自定义监听器，或覆写一些监听器的行为
        {
          click: function () {
            self.onClick()
          }
        }
      )
    }
  },
  methods: {
    onClick: function () {
      this.loading = true
      this.$emit('click', this.done)
    },
    done: function () {
      this.loading = false
    }
  }
}
</script>

<style>

</style>
